package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import model.Post;

public class PostDAO {
private Connection conn;

    public PostDAO(Connection conn) {
        this.conn = conn;
    }

    public boolean addPost(Post post) {
        String sql = "INSERT INTO posts (user_id, title, content) VALUES (?, ?, ?)";
        try {
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, post.getUserId());
            pstmt.setString(2, post.getTitle());
            pstmt.setString(3, post.getContent());
            int rowsAffected = pstmt.executeUpdate();
            return rowsAffected > 0;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    // 其他方法，如查询文章、更新文章信息等
}